<template>
  <div class="layui-layout layui-layout-admin">
    <div class="adminnav1">
      <Pagetop></Pagetop>
    </div>
    <div class="adminnav2">
      <Secondnav urlname="user"></Secondnav>
    </div>

    <!-- 主体内容 -->
    <div class="layui-body kedou-admin" id="LAY_app_body app">
      <div class="layadmin-tabsbody-item layui-show">
        <div class="pagelist">
          <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
              <legend>门店列表</legend>
            </fieldset>
          </div>
          <div class="pagetop">
            <Search :seadate="searchArr"></Search>
          </div>
          <div class="layui-card-body">
            <div class="buttop" v-show="isadd == 1" style="display:none;">
              <button type="button" class="layui-btn  layui-btn-normal" @click="addData">
                添加门店
              </button>
              <button type="button" class="layui-btn layui-btn-warm" @click="setData">
                门店设置
              </button>
              <button type="button" class="layui-btn layui-btn-danger" @click="dwData">
                下载
              </button>
            </div>
            <Tables :fdate="pdate" :result="res" height="430" :totalCount="totalRows" :pageNumber="curindex"
              :fbtn="btn"></Tables>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Pagetop from "../../common/pagetop.vue";
import Secondnav from "../../common/secondnav.vue";
import Tables from "../../common/tables.vue";
import Search from "../../common/search.vue";
export default {
  name: "storelist",
  components: { Pagetop, Secondnav, Tables, Search },
  data () {
    return {
      pdate: [], //表头
      res: "", //内容
      totalRows: "", //总数量
      curindex: 1, //页数
      btn: [], //按钮
      searchArr: [], //搜索
      isShow: false,
      seapram: "",
      type: localStorage.getItem("type"),
      level: localStorage.getItem("level"),
      dealerId: localStorage.getItem("dealerId"),
      isadd: 0
    };
  },
  mounted () {
    //alert(this.type+"//"+this.level)
    if (this.type == 2) {
      this.isadd = 1;
      //	  		if(this.level==0){
      //             this.isadd=0;
      //          }
    } else if (this.type == 3) {
      this.isadd = 1;
    } else {
      this.isadd = 0;
    }
    this.getdate();
    this.getsearch();
  },
  methods: {
    getdate: function () {
      var _this = this;
      var url = "/shop/papi/v1.9/shops";
      if (_this.seapram) {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          // sort:'createAt,DESC',
          'dealerId.equals':_this.dealerId
        };
        var res = _this.seapram;
        for (var i = 0; i < res.length; i++) {
          dates[res[i].key + '.equals'] = res[i].val;
        }
      } else {
        var dates = {
          size: pageSize,
          page: _this.curindex,
          //sort:'createAt,DESC',
          'dealerId.equals':_this.dealerId
        };
      }
      //alert(url+"//"+JSON.stringify(dates))
      ajaxRequest(url, "GET", "json", dates, function (ret, err) {
        //alert(url+"//"+JSON.stringify(ret))
        var arr = [];
        arr[0] = [
          { field: "id", title: "门店ID" },
          { field: "name", title: "门店名称" },
          {
            field: "dealer",
            title: "联系方式",
            templet: function (d) {
              return d.dealer.mobile;
            }
          },
          {
            field: "rotationPictures",
            title: "图片",
            templet:
              '<div><img src="{{d.rotationPictures}}" style="display: inline-block; height: 100%;"></div>'
          },
          {
            field: "activeStatus",
            title: "是否启用",
            templet: function (d) {
              if (d.activeStatus == "ENABLE") return "是";
              else return "否";
            }
          },
          {
            field: "perCapita",
            title: "人均消费(元)",
            templet: function (d) {
              return d.perCapita / 100;
            }
          },
          {
            field: "shopType",
            title: "店铺类型",
            templet: function (d) {
              return d.shopType.name;
            }
          },
          { field: "salesVolume", title: "全店销量" },
          { field: "score", title: "总评分" },
          {
            field: "createAt",
            title: "创建时间",
            templet: function (d) {
              return FormatDate(d.createAt, 2);
            }
          },
          {
            field: "right",
            title: "操作",
            width: "200",
            fixed: "right",
            templet: function (d) {
              var str =
                '<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">编辑</a>';
              var str1 =
                '<a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="detail">商城栏目设置</a>';
              if (d.activeStatus == "ENABLE") {
                str =
                  str +
                  '<a class="layui-btn layui-btn-xs" lay-event="enable">启用</a>';
              } else {
                str =
                  str +
                  '<a class="layui-btn layui-btn-xs" lay-event="enable">禁用</a>';
              }
              return str +str1;
            }
          }
        ];
        _this.pdate = arr;
        _this.res = ret.data.list; //res1;
        _this.totalRows = ret.data.totalRows;
        _this.curindex = ret.data.pageNumber;
      });
    },
    getsearch: function () {
      var arr = [{ field: "name", title: "门店名称", type: "input" }];
      this.searchArr = arr;
    },
    page: function (index, obj) {
      //alert(JSON,stringify(obj))
      this.curindex = index;
      this.getdate();
    },
    sousuo: function (pram) {
      //alert(JSON.stringify(pram))
      this.seapram = pram;
      this.res = "";
      this.totalRows = "";
      this.curindex = "";
      this.getdate();
    },
    addData: function () {
      if (this.res.length > 0 && this.type == 2) {
        layer.msg("个体商家只能开通一个门店");
      } else if (this.type == 6) {
        layer.msg("不能新增门店");
      } else {
        this.$router.push({ path: "/storedit" });
      }
    },
    setData: function (data) {
      var vm = this;
      layer.open({
        type: 2,
        title: "申请列表",
        content: baseurl + "/shopsetem",
        area: vm.screens() < 2 ? ["60%", "80%"] : ["600px", "800px"],
        success: function (layero, index) {
          var ifremeWin = window[layero.find("iframe")[0]["name"]];
          ifremeWin.getdates(data);
        }
      });
    },
    dwData: function (data) {
      var vm = this;
      layer.open({
        type: 2,
        title: "下载列表",
        content: baseurl + "/shopdw",
        area: vm.screens() < 2 ? ["65%", "80%"] : ["650px", "800px"],
        success: function (layero, index) {
          var ifremeWin = window[layero.find("iframe")[0]["name"]];
          ifremeWin.getdates(data);
        }
      });
    },
    editInfo: function (data) {
      //		this.$router.push({path:'/storedit'})
      var _this = this;
      var id = data.id;
      this.$router.push({
        path: "/storedit",
        query: {
          id: id
        }
      });
    },
    detailInfo: function (data) {
       var _this = this;
      var id = data.id;
      this.$router.push({
        path: "/storetype",
        query: {
          id: id
        }
      });
      
    },
    enableInfo: function (data) {
      var vm = this;
      //   var id = data.id;
      if (data.activeStatus == "ENABLE") {
        var activeStatus = "DISABLE";
      } else {
        var activeStatus = "ENABLE";
      }
      var url =
        "/shop/bapi/v1.9/shops/updateShopActiveStatus/" +
        data.id +
        "/" +
        activeStatus;
      ajaxRequest(url, "PUT", "json", "", function (ret, err) {
        layer.msg("操作成功");
        setTimeout(function () {
          vm.getdate();
        }, 1000);
      });
    },
    screens: function () {
      return screen();
    }
  },
  updated: function () {
    this.isShow = true;
    layui.use("form", function () {
      var form = layui.form;
      form.render();
      //   form.on("select(activeStatus)", function(data) {
      //     vm.itemData.activeStatus = data.value;
      //     //	var name=data.elem.getAttribute('name');
      //   });
    });
  }
};
</script>
<style scoped>
/**/
</style>
